﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace TMI85303.Utils
{
    public class Configurations
    {
        public static int MTP4 { get; set; } = 0;
        public static int MTP6 { get; set; } = 0;
        public static int MTP7 { get; set; } = 0;
        public static int MTP8 { get; set; } = 0;
        public static int MTP9 { get; set; } = 0;
        public static int MTP10 { get; set; } = 0;
        public static int MTP11 { get; set; } = 0;
        public static int MTP12 { get; set; } = 0;
        public static int MTP13 { get; set; } = 0;
        public static int MTP14 { get; set; } = 0;
        public static int MTP15 { get; set; } = 0;
        public static int MTP16 { get; set; } = 0;
        public static int MTP17 { get; set; } = 0;
        public static int MTP18 { get; set; } = 0;
        public static int MTP19 { get; set; } = 0;
        public static int MTP20 { get; set; } = 0;
        public static int MTP21 { get; set; } = 0;
        public static int MTP22 { get; set; } = 0;
        public static int MTP23 { get; set; } = 0;
        public static int MTP24 { get; set; } = 0;
        public static int MTP25 { get; set; } = 0;
        public static int MTP26 { get; set; } = 0;
        public static int MTP27 { get; set; } = 0;
        public static int MTP29 { get; set; } = 0;
        public static int MTP30 { get; set; } = 0;

        public static int Counts0 { get; set; } = 0;
    }

    public static class GlobalApp
    {
        /// <summary>
        /// 在UI线程中使用的公共数据库连接对象
        /// </summary>
        //public static SQLiteHelper? uiSQLiteConn { get; set; }

        public static string Version { get; } = ("V" + Assembly.GetExecutingAssembly().GetName().Version?.ToString()) ?? "";
        public static string ChipName { get; } = "TMI85303";
        public static string MainWindowTitle { get; } = ChipName + " " + Version;
        public static DateTime? BuildTime { get; set; }
    }

    public class PathHelper
    {
        public static string IniPath { get; set; } = AppDomain.CurrentDomain.BaseDirectory + "SetPort.ini";
        public static string DbPath { get; set; } = AppDomain.CurrentDomain.BaseDirectory + "TMI85303.db";
        public static string FaultSpeedPath { get; set; } = AppDomain.CurrentDomain.BaseDirectory + "FaultCode.ini";
        public static string DubugConfigFolder { get; set; } = AppDomain.CurrentDomain.BaseDirectory + "Configuration example\\";

    }

    public static class CommFun
    {
        /// <summary>
        /// 获取程序当前程序版本号
        /// </summary>
        /// <returns></returns>
        public static string AssemblyFileVersion()
        {

            // string str = Assembly.GetExecutingAssembly().FullName;

            var versions = Assembly.GetExecutingAssembly().GetName().Version;
            return $"{versions.Major}.{versions.Minor}.{versions.Build}.{versions.Revision}";

        }

        public static bool IsFirstRun()
        {
            var targetLanguage = ConfigurationManager.AppSettings["FirstRun"];
            return !string.IsNullOrEmpty(targetLanguage) && targetLanguage == "true";
        }

        public static void UpdateAppConfigFirstRunSetting()
        {
            Configuration _configuration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
            _configuration.AppSettings.Settings["FirstRun"].Value = "false";
            _configuration.Save();
            ConfigurationManager.RefreshSection("appSettings");
        }

    }

    public static class Lang
    {
        public const string Chinese = "zh-CN";
        public const string English = "en-US";
    }
}
